home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 9 / 009.d81 / pps #21 < prev    next >
Text File  |  2022-08-26  |  4KB  |  271 lines

  1.  
  2.  PEEKs, POKEs, and SYSes  -- Part 21
  3.  
  4.           by Jimmy Weiler
  5.  
  6.  
  7.  
  8. ======================================
  9.  
  10.     JIMMY WEILER'S INPUT ANYSTRING
  11.  
  12. --------------------------------------
  13.  
  14.   We will begin by 'zeroing out' the
  15.  
  16. string where we want to place our
  17.  
  18. input.  That is to get rid of any
  19.  
  20. residual contents from previous INPUTs
  21.  
  22. into the string.  While we're at it,
  23.  
  24. let's define a space and a backspace
  25.  
  26. for use later.
  27.  
  28.  
  29. 5 L$="":S$=" ":B$=CHR$(157)
  30.  
  31.  
  32.   Next, we start GETting letters from
  33.  
  34. the keyboard.  We want to make sure
  35.  
  36. the cursor is blinking, too.
  37.  
  38.  
  39. 25 POKE 204,0: GET K$: K = PEEK(203)
  40.  
  41.  
  42. Location 204 is BLNSW.  A value of
  43.  
  44. zero in BLNSW tells the Commodore to
  45.  
  46. flash the cursor during a GET.
  47.  
  48. Location 203 is SFDX.  We will be
  49.  
  50. using that value, stored in the
  51.  
  52. variable K to determine what key was
  53.  
  54. pressed.
  55.  
  56.   If no key was pressed, then K$ will
  57.  
  58. be an empty string and we will want
  59.  
  60. to GET another keypress.
  61.  
  62.  
  63. 40 IF K$ = "" THEN 25
  64.  
  65.  
  66.   If K$ is not equal to a null string,
  67.  
  68. that means a key was pressed, and it
  69.  
  70. is time to figure out what to do with
  71.  
  72. it.  Before we do anything, we'll
  73.  
  74. RESET the quote flag.  That way, if
  75.  
  76. the last letter printed was a quote,
  77.  
  78. the next cursor control printed will
  79.  
  80. be a true cursor control, and not
  81.  
  82. a graphics image.
  83.  
  84.  
  85. 45 POKE 212,0
  86.  
  87.  
  88.   If K$ is a carriage return, then
  89.  
  90. the input is finished and we should
  91.  
  92. exit the routine.  It is good form to
  93.  
  94. have subroutine RETURNS occur only at
  95.  
  96. the end of the subroutine, so we will
  97.  
  98. GOTO that RETURN statement.  We print
  99.  
  100. a space followed by a backspace to
  101.  
  102. erase the cursor, in case you press
  103.  
  104. <RETURN> when the cursor is on.
  105.  
  106.  
  107. 50 IF K$ = CHR$(13) THEN PRINT S$B$
  108.    :GOTO 90
  109.  
  110.  
  111.   If K$ is a backspace, we want to
  112.  
  113. lop off the last letter we typed, if
  114.  
  115. we have, indeed, typed any.
  116.  
  117.  
  118. 55 IFK$=B$THEN ON ABS(LEN(L$)=0)GOTO25
  119. :L$=LEFT$(L$,LEN(L$)-1):?K$S$;:GOTO80
  120.  
  121.  
  122. ABS(LEN(L$)=0) is equal to 1 if L$ is
  123.  
  124. a null string.  If so, we can't take
  125.  
  126. any more off the end, so we don't even
  127.  
  128. try -- we just jump back to the GET
  129.  
  130. statement in 25.
  131.  
  132.   If L$ did have any characters in it,
  133.  
  134. L$=LEFT$(L$,LEN(L$)-1) will lop the
  135.  
  136. last one off.  Then ?K$" " will erase
  137.  
  138. the last character displayed on the
  139.  
  140. screen.
  141.  
  142.   If K$ was not a carriage return and
  143.  
  144. not a backspace, we want to start
  145.  
  146. thinking about adding it to the end of
  147.  
  148. L$, but first we better check to see
  149.  
  150. if L$ can stand another letter.  The
  151.  
  152. longest string Commodore BASIC allows
  153.  
  154. is 255 characters.  If our string is
  155.  
  156. already that long, we can't tack any
  157.  
  158. more letters onto it so we just go
  159.  
  160. back to waiting for a keypress..
  161.  
  162.  
  163. 60 IF LEN(L$)=255 THEN 25
  164.  
  165.  
  166.   Now, let's check all the keys we
  167.  
  168. want to ignore and see if the key
  169.  
  170. pressed was one of them.  This is
  171.  
  172. where we use the variable K, which we
  173.  
  174. set equal to PEEK(203) -- the NUMBER
  175.  
  176. of the key being pressed.  If you look
  177.  
  178. back at the SFDX key value chart, you
  179.  
  180. will see that most of the special
  181.  
  182. keys are right at the beginning.  In
  183.  
  184. fact, the ones we want to ignore are
  185.  
  186. 0 through 7, and 51, the clear/home
  187.  
  188. key.  (It's always very confusing to
  189.  
  190. the user if you let him accidentally
  191.  
  192. clear the screen.)
  193.  
  194.  
  195. 70 ON ABS(K<8 OR K=51) GOTO 25
  196.  
  197.  
  198.  which is just another way of saying
  199.  
  200.  
  201. 70 IF (K<8 OR K=51) THEN 25
  202.  
  203.  
  204.   This effectively causes our routine
  205.  
  206. to take no further notice of INS/DEL,
  207.  
  208. <RETURN>,<CRSR>,function keys,or
  209.  
  210. CLR/HOME.  If any of those were
  211.  
  212. pressed, the program will just go back
  213.  
  214. to the GET statement to wait for
  215.  
  216. another keypress.
  217.  
  218.   Now that we're sure the key pressed
  219.  
  220. is a real letter or character, we can
  221.  
  222. add it to the end of L$.
  223.  
  224.  
  225. 75 L$ = L$ + K$
  226.  
  227.  
  228.   Then there's nothing left to do
  229.  
  230. but clean up any unwanted characters
  231.  
  232. at the end of the line of input, and
  233.  
  234. loop back to the GET statement.
  235.  
  236.  
  237. 80 PRINT S$B$K$;
  238. 85 GOTO 25
  239.  
  240.  
  241.   And finally we return with the
  242.  
  243. completely assembled string in L$.
  244.  
  245.  
  246. 90 RETURN
  247.  
  248.  
  249. --------------------------------------
  250.  
  251. Try taking out the backspaces, or
  252.  
  253. don't check for the invalid characters
  254.  
  255. and see what happens.  You should be
  256.  
  257. able to adapt this or write something
  258.  
  259. like it to fit nearly any application.
  260.  
  261. This entire subroutine is available
  262.  
  263. to you on this disk.  It is saved onto
  264.  
  265. SIDE 2 as 'JIMMY'S INPUT AN'.
  266.  
  267.   Hope you have learned something!!
  268.  
  269.  
  270. ---------< end of article >-----------
  271.